package com.ruoyi.project.system.messageinfo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.messageinfo.domain.MessageInfo;
import com.ruoyi.project.system.messageinfo.service.IMessageInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 留言内容Controller
 * 
 * @author LCL
 * @date 2021-10-08
 */
@Controller
@RequestMapping("/system/messageinfo")
public class MessageInfoController extends BaseController
{
    private String prefix = "system/messageinfo";

    @Autowired
    private IMessageInfoService messageInfoService;

    @RequiresPermissions("system:messageinfo:view")
    @GetMapping()
    public String messageinfo()
    {
        return prefix + "/messageinfo";
    }

    /**
     * 查询留言内容列表
     */
    @RequiresPermissions("system:messageinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MessageInfo messageInfo)
    {
        startPage();
        List<MessageInfo> list = messageInfoService.selectMessageInfoList(messageInfo);
        return getDataTable(list);
    }

    /**
     * 导出留言内容列表
     */
    @RequiresPermissions("system:messageinfo:export")
    @Log(title = "留言内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MessageInfo messageInfo)
    {
        List<MessageInfo> list = messageInfoService.selectMessageInfoList(messageInfo);
        ExcelUtil<MessageInfo> util = new ExcelUtil<MessageInfo>(MessageInfo.class);
        return util.exportExcel(list, "messageinfo");
    }

    /**
     * 新增留言内容
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存留言内容
     */
    @RequiresPermissions("system:messageinfo:add")
    @Log(title = "留言内容", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MessageInfo messageInfo)
    {
        return toAjax(messageInfoService.insertMessageInfo(messageInfo));
    }

    /**
     * 修改留言内容
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        MessageInfo messageInfo = messageInfoService.selectMessageInfoById(id);
        mmap.put("messageInfo", messageInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存留言内容
     */
    @RequiresPermissions("system:messageinfo:edit")
    @Log(title = "留言内容", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MessageInfo messageInfo)
    {
        return toAjax(messageInfoService.updateMessageInfo(messageInfo));
    }

    /**
     * 删除留言内容
     */
    @RequiresPermissions("system:messageinfo:remove")
    @Log(title = "留言内容", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(messageInfoService.deleteMessageInfoByIds(ids));
    }
}
